%% Sample Script
%
% An example of function calls to readFromCSV_TELE, UNSW_ArtifactMask and
% UNSW_QRSDetector
%
% If you use this code or data, please cite as follows:
%
% [1] H. Khamis, R. Weiss, Y. Xie, C-W. Chang, N. H. Lovell, S. J. Redmond, 
% "QRS detection algorithm for telehealth electrocardiogram recordings," 
% IEEE Transaction in Biomedical Engineering, vol. 63(7), p. 1377-1388,
% 2016.
%
% Last Modified: 05/09/2016
%

% Extract the data from .dat files into a struct
[DB,fm,fs,rail_mv] = readFromCSV_TELE('.');

% For the first entry in the database...
raw_ecg = DB(1).ecg_mv;
stored_mask_locs = find(DB(1).software_mask);

% Calculate the software artifact mask
[rcmask,hfmask,lpmask,bsmask,finalmask] = UNSW_ArtifactMask(raw_ecg,rail_mv,fm,fs);
calculated_mask_locs = finalmask;

% Compare the software artifact mask stored with the .dat files to the one
% calculated using the code supplied
if length(stored_mask_locs) ~= length(calculated_mask_locs) | ~isempty(find(stored_mask_locs - calculated_mask_locs))
    error('The stored software mask does not match the calculated mask - CODE MISMATCH!');
end

% Run the QRS detector
[qrs,RRlist,nRR,mRR,nSections] = UNSW_QRSDetector(raw_ecg,fs,stored_mask_locs,true);


